package com.kingyun.gpsinspection.purificationservice.services.iam.outerservice.adm;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.iam.adm.MessageMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.iam.adm.RelationMessageMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.iam.adm.RelationMessage;
import com.kingyun.gpsinspection.purificationservice.facade.service.iam.adm.OutRelationMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version V1.0
 * @Package com.cqhilink.iot.integratedapplicationmanagement.services.innerservice.adm.impl
 * @Description: ${TODO}(通告服务实现)
 * @author: lutianbo
 * @date: 2017/3/20,0020
 */
@Service
public class OutRelationMessageServiceImpl implements OutRelationMessageService{
    @Autowired
    private MessageMapper  messageMapper;
    @Autowired
    private RelationMessageMapper relationMessageMapper;

    /**
     * 根据主键查询信息
     * @param message 主键id
     * @return
     */
    @Override
    public RelationMessage selectByPrimaryKey(RelationMessage message){
        if(message != null){
            message = relationMessageMapper.selectByPrimaryKey(message);
            return message;
        }
        return null;
    }

    @Override
    public JSONObject list(RelationMessage message)
    {
        JSONObject jsonObject = new JSONObject();
        // 分页设置
        message.setLimit(message.getLimit() == null ? Integer.valueOf(10) : message.getLimit());
        message.setOffset(message.getOffset() == null ? Integer.valueOf(0) : message.getOffset());
        // 总条数
        jsonObject.put("total", relationMessageMapper.queryCount(message));
        List<RelationMessage> trainList = relationMessageMapper.queryList(message);
        jsonObject.put("rows", JSON.toJSON(trainList));
        return jsonObject;
    }
}
